#include "piece.h"

// DEBUG
#include <iostream>
using namespace std;

#include "../partie.h"

Piece::Piece(Partie * parent, int x, int y, Couleur couleur) {
    this->parent = parent;
    this->x = x;
    this->y = y;
    this->couleur = couleur;
}

int Piece::getX() {
    return x;
}
int Piece::getY() {
    return y;
}
Type Piece::getType() {
    return this->type;
}
Couleur Piece::getCouleur() {
    return couleur;
}

void Piece::setX(int x) {
    this->x = x;
}
void Piece::setY(int y) {
    this->y = y;
}

void Piece::ajouterCoup(bool suppr_echecs, int x, int y, Coup coup) {
    //parent->matriceDepl[x][y] = coup;
    //cout << "deplacement : " << x << " " << y << " " << coup << endl;
    parent->setDepl(x,y,coup);

    /*** + SUPPRIMER SI COUP EN ECHEC ***/
    if (suppr_echecs) {
        if (coup != CASE_ACTUELLE) {
            //cout << "suppr_echecs" << endl;
            //cout << "deplacerPiece()" << endl;
            parent->deplacerPiece(this, x, y, true);
            //cout << "verifierEchec()" << endl;
            //if (parent->verifierEchec(couleur==BLANC?NOIR:BLANC)) { // si echec !!!
            if (parent->verifierEchec(couleur)) { // si echec !!!
                cout << "Coup en echec retire : " << x << " " << y << endl;
                parent->setDepl(x,y,AUCUN_COUP);
            }
            //cout << "annulerDeplacement()" << endl;
            parent->annulerDeplacement();
        }
    }
}
